<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>年会随机抽奖案例</title>
    <style>
        .wrapper {
            width: 840px;
            height: 420px;
            background: url(./images/bg01.jpg) no-repeat center / cover;
            padding: 100px 250px;
            box-sizing: border-box;
            margin: 100px auto;
        }
    </style>
</head>

<body>
    <div class="wrapper">
        <strong>年会抽奖</strong>
        <h1>一等奖：<span id="one">???</span></h1>
        <h3>二等奖：<span id="two">???</span></h3>
        <h5>三等奖：<span id="three">???</span></h5>
    </div>

    <script>
        // 定义数组
        let personArr = ['小胡胡', '大胡胡', '小强强', '大强强']
        // // 抽取一等奖
        // const random = Math.floor(Math.random() * personArr.length)
        // // 获取one元素
        // const one = document.querySelector('#one')
        // // 将文本信息插入one元素
        // one.innerHTML = personArr[random]
        // // 从数组中删除
        // personArr.splice(random, 0)

        for (let i = 0; i < 3; i++) {
            // 抽奖
            const random = Math.floor(Math.random() * personArr.length)
            // 获取span元素
            const spans = document.querySelectorAll('span')
            // 将文本信息插入span元素.
            spans[i].innerHTML = personArr[random]
            // 从数组中删除
            personArr.splice(random, 1)
        }
    </script>

</body>

</html>